package tech.yangzhijie.basic.knowledge.mianshi;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

public class Test15LockSupport {

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("进入" + Thread.currentThread().getName() + " 线程");
            System.out.println("线程" + Thread.currentThread().getName() + " 等待………");
            LockSupport.park();

            System.out.println("线程" + Thread.currentThread().getName() + " 结束");
        });

        t1.start();

        new Thread(()->{
            System.out.println("进入" + Thread.currentThread().getName() + " 线程");
            System.out.println("线程" + Thread.currentThread().getName() + " 唤醒线程 " + t1.getName());
            LockSupport.unpark(t1);
            System.out.println("线程" + Thread.currentThread().getName() + " 结束");
        }).start();
    }
}
